// vue-router@4写法稍有变化
import { createRouter, createWebHistory } from 'vue-router';
const routes = [
    {
        path: '/register',
        name: 'register',
        component: () => import('@/views/Register.vue')
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/Login.vue')
    },
    {
        path: '/home',
        name: 'home',
        component: () => import('@/views/Home.vue'),
        children: [
            {
                path: 'right/:id',
                name: 'right',
                component: () => import('@/views/home/Right.vue'),
                beforeEnter: () => {
                    // ...
                    console.log('单独路由独享');
                }
            },
            {
                path: '/home/left',
                name: 'left',
                component: () => import('@/views/home/Left.vue')
            }
        ]
    },
    {
        path: '/',
        redirect: {
            path: '/home'
        }
    }
]


const router = createRouter({
    // hash模式   上面记得引入
    // history: createWebHashHistory(),
    // history模式
    history: createWebHistory(),
    routes
})

// 全局守卫
router.beforeEach((to, from, next) => {
    console.log(to);
    console.log(from);
    next();
})

export default router;